package assignment.ton.gui;


import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import assignment.ton.def.Action;
import assignment.ton.def.Util;
import assignment.ton.gui.listener.MenuActionListener;
/**
 * The top menu bar, uses menu action listener
 */
public class MenuBar extends JMenuBar{
	private static final long serialVersionUID = 1L;
	private JMenu file, edit, help;
	private JMenuItem newItem,saveItem,openItem,exportItem,undoItem,redoItem,quitItem,printItem,indexItem,aboutItem;
	private MenuActionListener menulistener;
	private MainFrame mainFrame;
	private JLabel task;
	public MenuBar(MainFrame mF){
		mainFrame = mF;
		file = new JMenu("File");
		edit = new JMenu("Edit");
		help = new JMenu("Help");
		task = new JLabel("Current Task: None  ");
		menulistener = new MenuActionListener(mainFrame);
		this.add(file);
		this.add(edit);
		this.add(help);
		this.add(Box.createHorizontalGlue());
		this.add(task);
		//file menu
		newItem = new JMenuItem("New");
		file.add(newItem);
		newItem.addActionListener(menulistener);
		saveItem = new JMenuItem("Save");
		file.add(saveItem);
		saveItem.addActionListener(menulistener);
		openItem = new JMenuItem("Open");
		file.add(openItem);
		openItem.addActionListener(menulistener);
		exportItem = new JMenuItem("Export");
		file.addSeparator();
		file.add(exportItem);
		exportItem.addActionListener(menulistener);
		file.addSeparator();
		printItem = new JMenuItem("Print");
		printItem.addActionListener(menulistener);
		file.add(printItem);
		file.addSeparator();
		quitItem = new JMenuItem("Quit");
		file.add(quitItem);
		quitItem.addActionListener(menulistener);
		//edit menu
		undoItem = new JMenuItem("Undo");
		edit.add(undoItem);
		undoItem.addActionListener(menulistener);
		redoItem = new JMenuItem("Redo");
		edit.add(redoItem);
		redoItem.addActionListener(menulistener);
		//help menu
		indexItem = new JMenuItem("Index");
		indexItem.addActionListener(menulistener);
		help.add(indexItem);
		aboutItem = new JMenuItem("About");
		aboutItem.addActionListener(menulistener);
		help.add(aboutItem);
	}
	/**
	 * @param a action to make readable and set the text for the top right
	 */
	public void setTaskLabel(Action a){
		task.setText("Current Task: "+Util.actionToString(a, mainFrame)+"  ");
	}
}
